home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* AmigaEyes V1.1a (02/12/1994) */
- /* */
- /* Author: Stéphane Poirier */
- /* Copyright © 1994 Stéphane Poirier. All right reserved */
- /* */
- /*****************************************************************************/
-
- /*****************************************************************************/
- /* Programme principal */
- /*****************************************************************************/
-
- #include <libraries/commodities.h>
- #include <exec/types.h>
- #include <ctype.h>
- #include <intuition/intuition.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/gadgetclass.h>
- #include <libraries/gadtools.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/icon_protos.h>
- #include <clib/utility_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/commodities_protos.h>
- #include <string.h>
- #include <clib/diskfont_protos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <exec/memory.h>
- #include <workbench/workbench.h>
- #include <workbench/startup.h>
- #include <time.h>
-
- #include "eyes.h"
-
- struct parametres Parametres;
- unsigned int clockInit[2];
- USHORT refresh;
-
- extern int EyeCloseWindow(void);
- void ToolTypesParameters(struct WBArg *);
- void ValeursParDefaut(void);
- int EyesInfo(void);
- int EyesGoPublic(void);
- int AutoJump(void);
- void OpenLibs(void);
- void CloseLibs(void);
- void SortiePropre(void);
-
- UBYTE *toolTypes[]=
- {
- "AUTOFRONT=ON|OFF",
- "AUTOJUMP=ON|OFF",
- "TIMEOUT=n",
- "BACKGROUND=n",
- "BORDER=n",
- "PUPIL=n",
- "EYELIP=n",
- "WINDOW=n",
- "XPOS=n",
- "YPOS=n",
- "PRIORITY=n",
- "REFRESH=n",
- "CUSTOM_DRAWING",
- "HOTKEY",
- NULL
- };
-
- struct Library *GfxBase;
- struct Library *DosBase;
- struct Library *CxBase = NULL;
-
- UBYTE hotkey[64] = "alt $";
-
- struct Screen *ActiveScreen;
-
- static struct Screen *Scr = NULL;
- static UBYTE *PubScreenName = NULL;
- static APTR VisualInfo = NULL;
- static struct Window *EyeWnd = NULL;
- static struct Menu *EyesMenu = NULL;
- static struct BitMap SBitmap;
- struct IntuiMessage EyeMsg;
- static struct TextFont *Font = NULL;
- static UWORD EyeLeft = 530;
- static UWORD EyeTop = 2;
- static UWORD EyeWidth = 94;
- static char *Version = "$VER: AmigaEyes 1.1a";
- static char PublicName[128];
- static char PublicNameInit[128];
-
- BOOL Restart = TRUE;
- BOOL ModifyPub = FALSE;
- struct Task *task;
-
- #ifdef ENTRELACE
- static UWORD EyeHeight = 40;
- #else
- static UWORD EyeHeight = 23;
- #endif
-
- /*
- ** Titre de la fenêtre
- */
- static UBYTE *EyeWdt = (UBYTE *)"Eyes";
-
- /*
- ** Définition du menu
- */
- static struct NewMenu EyesNewMenu[] = {
- NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
- NM_ITEM, (STRPTR)"-> Default PubScreen", (STRPTR)"P", 0, NULL, EyesGoPublic,
- NM_ITEM, (STRPTR)"AutoJump", NULL, CHECKIT, NULL, (APTR)AutoJump,
- NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
- NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, 0L, (APTR)EyesInfo,
- NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
- NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)EyeCloseWindow,
- NM_END, NULL, NULL, 0, 0L, NULL };
-
- /*****************************************************************************/
-
- void errorMessage(STRPTR error)
- {
- if (error)
- printf("Error: %s\n", error);
- }
-
- /*****************************************************************************/
-
- int SetupScreen( void )
- {
- if ( ! ( Scr = LockPubScreen( PubScreenName )))
- return( 1L );
-
- if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
- return( 2L );
-
- return( 0L );
- }
-
- /******************************************************************************/
- /* Gestion des évenements Intuition */
- /******************************************************************************/
- int HandleEyeIDCMP( void )
- {
- int (*func)(void);
- struct MenuItem *n;
- struct IntuiMessage *m;
- BOOL running = TRUE;
-
- while( m = GT_GetIMsg( EyeWnd->UserPort )) {
-
- CopyMem(( char * )m, ( char * )&EyeMsg, (long)sizeof( struct IntuiMessage ));
-
- GT_ReplyIMsg( m );
-
- switch ( EyeMsg.Class ) {
-
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh( EyeWnd );
- GT_EndRefresh( EyeWnd, TRUE );
- break;
-
- case IDCMP_CLOSEWINDOW:
- running = FALSE;
- Restart = TRUE;
- Dodo = TRUE;
- break;
-
- case IDCMP_MENUPICK:
- while( EyeMsg.Code != MENUNULL ) {
- n = ItemAddress( EyesMenu, EyeMsg.Code );
- func = (int (*) (void))(GTMENUITEM_USERDATA( n ));
- running = func();
- EyeMsg.Code = n->NextSelect;
- }
- break;
- }
- }
- return( running );
- }
-
- /******************************************************************************/
- /* Ouverture de la fenêtre */
- /******************************************************************************/
- int OpenEyeWindow( void )
- {
- UWORD offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
-
- if (! ( EyesMenu = CreateMenus( EyesNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
- return(0L);
-
- LayoutMenus( EyesMenu, VisualInfo, TAG_DONE );
-
- if ( ! ( EyeWnd = OpenWindowTags( NULL,
- WA_Left, EyeLeft,
- WA_Top, EyeTop,
- WA_Width, EyeWidth,
- WA_Height, EyeHeight + offy,
- WA_SuperBitMap, &SBitmap,
- WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_MENUPICK,
- WA_Flags, WFLG_GIMMEZEROZERO|WFLG_DRAGBAR|WFLG_SUPER_BITMAP|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_REPORTMOUSE,
- WA_Title, EyeWdt,
- WA_NewLookMenus, TRUE,
- WA_ScreenTitle, " Big Brother is watching you !",
- WA_PubScreen, Scr,
- TAG_DONE )))
- return( 0L );
-
- GT_RefreshWindow( EyeWnd, NULL );
- SetMenuStrip( EyeWnd, EyesMenu );
-
- return( (int)offy );
- }
-
-
- /******************************************************************************/
- /* Sélection de l'option de menu 'AutoJump' */
- /******************************************************************************/
- void AutoJumpMenu(BOOL CheckMark)
- {
- struct MenuItem *Item;
- UWORD Flags;
-
- ClearMenuStrip(EyeWnd);
- Item = EyesMenu->FirstItem->NextItem;
- Flags = Item->Flags;
-
- if (CheckMark)
- Flags |= CHECKED;
-
- Item->Flags = Flags;
-
- ResetMenuStrip(EyeWnd, EyesMenu);
- }
-
- /******************************************************************************/
- /* Change l'état de l'indicateur 'autojump' */
- /******************************************************************************/
- int AutoJump(void)
- {
- if (Parametres.autojump == TRUE)
- {
- Parametres.autojump = FALSE;
- }
- else
- {
- Parametres.autojump = TRUE;
- }
- return(1L);
- }
-
- /******************************************************************************/
- /* Effectue la fonction de saut sur l'écran public actif au cas ou celui-ci */
- /* a changé. */
- /******************************************************************************/
- int ProcessJump(BOOL Force)
- {
- struct List *PubList;
- struct PubScreenNode *PubNode;
- struct Screen *ActiveScr = NULL;
- BOOL Loop = TRUE;
- char ScrName[128];
- BOOL PubOk = FALSE, running = TRUE;
- static UWORD DelaiJump = 0;
-
- if (Force)
- {
- DelaiJump += refresh;
- if (DelaiJump < 50) return (running);
- }
-
- DelaiJump = 0;
-
- /*
- ** Récupère l'adresse de l'écran actif (avant plan)
- */
- while (ActiveScr == NULL)
- {
- LockIBase(0);
- ActiveScr = ((struct IntuitionBase *)IntuitionBase)->ActiveScreen;
- UnlockIBase(0);
- if (!ActiveScr) Delay(SLEEP);
- }
-
- if (ActiveScreen != ActiveScr)
- {
- /*
- ** Récupère un pointeur sur la liste des écrans publics
- */
- PubList = LockPubScreenList();
- PubNode = (struct PubScreenNode *)PubList->lh_Head;
-
- /*
- ** Recherche à quel écran public correspond l'écran actif
- */
- while (Loop)
- {
- if (PubNode)
- {
- if (ActiveScr == PubNode->psn_Screen)
- {
- /*
- ** On a trouvé !
- */
- Loop = FALSE;
- strcpy(ScrName, PubNode->psn_Node.ln_Name);
- PubOk = TRUE;
- }
- }
- else
- {
- Loop = FALSE;
- }
-
- if (Loop) PubNode = (struct PubScreenNode *)PubNode->psn_Node.ln_Succ;
- }
-
- /*
- ** Libère la liste des écrans publics
- */
- UnlockPubScreenList();
-
- /*
- ** Si on a trouvé l'écran public...
- */
- if (PubOk)
-
- /*
- ** Si celui-ci n'est pas l'écran actif
- */
- if (strcmp(ScrName, PublicNameInit) !=NULL)
- {
- GetDefaultPubScreen(PublicName);
- SetDefaultPubScreen(ScrName);
- Restart = TRUE;
- ModifyPub = TRUE;
- EyeCloseWindow();
- running = FALSE;
- Dodo = FALSE;
- strcpy(PublicNameInit, ScrName);
- ActiveScreen = ActiveScr;
- }
- }
-
- return (running);
- }
- /*****************************************************************************/
- int ProcessActive(void)
- {
- struct List *PubList;
- struct PubScreenNode *PubNode;
- struct Screen *ActiveScr;
- BOOL Loop = TRUE;
- char ScrName[128];
- BOOL PubOk = FALSE, running = TRUE;
-
- LockIBase(0);
- ActiveScr = ((struct IntuitionBase *)IntuitionBase)->ActiveScreen;
- UnlockIBase(0);
-
- PubList = LockPubScreenList();
- PubNode = (struct PubScreenNode *)PubList->lh_Head;
-
- while (Loop)
- {
- if (PubNode)
- {
- if (ActiveScr == PubNode->psn_Screen)
- {
- Loop = FALSE;
- strcpy(ScrName, PubNode->psn_Node.ln_Name);
- PubOk = TRUE;
- }
- }
- else
- {
- Loop = FALSE;
- }
-
- if (Loop) PubNode = (struct PubScreenNode *)PubNode->psn_Node.ln_Succ;
- }
-
- UnlockPubScreenList();
-
- if (PubOk)
- {
- GetDefaultPubScreen(PublicName);
- SetDefaultPubScreen(ScrName);
- Restart = TRUE;
- ModifyPub = TRUE;
- EyeCloseWindow();
- running = FALSE;
- strcpy(PublicNameInit, ScrName);
- }
-
- return (running);
- }
-
-
- /*****************************************************************************/
-
- void main(int argc, char **argv)
- {
- struct WBArg *wbarg;
-
- struct WBStartup *WBenchMsg;
-
- LONG i;
- int ret, offy, depth;
- BOOL running;
- BOOL reveil;
-
- OpenLibs();
- ValeursParDefaut(); /* Valeurs par défaut */
-
- WBenchMsg = (struct WBStartup *)argv; /* Arguments du Wb */
- wbarg = WBenchMsg->sm_ArgList;
-
- for(i = 0; i < WBenchMsg->sm_NumArgs; i++, wbarg++)
- ToolTypesParameters(wbarg); /* ToolTypes ! */
-
- StartCommodity();
-
- while (Restart)
- {
- /*
- ** Attend un peu, le temps que l'écran public soit bien en place
- */
- Delay(SLEEP);
-
- running = TRUE;
- GetDefaultPubScreen(PublicNameInit);
-
- if ((ret = SetupScreen()) == NULL)
- {
- if (ModifyPub)
- {
- SetDefaultPubScreen(PublicName);
- ModifyPub = FALSE;
- }
-
- ret = timer(clockInit); /* initialise l'horloge */
-
- depth = Scr->RastPort.BitMap->Depth; /* Initialise ma... */
- InitBitMap(&SBitmap, depth, WNDX, WNDY); /* superbitmap */
- for (i = 0; i < depth; i++)
- if((SBitmap.Planes[i] = AllocRaster(WNDX, WNDY)) == NULL)
- printf("erreur\n");
-
- if ((offy = OpenEyeWindow()) != NULL) /* Initialise ma fenêtre */
- {
- if (Parametres.autojump) AutoJumpMenu(TRUE);
-
- InitEyes(EyeWnd,&SBitmap);
- InitPlot(EyeWnd,&SBitmap);
- reveil = DrawingEyes(EyeWnd, &SBitmap, offy);
- Restart = FALSE;
- while (running == TRUE)
- {
- Delay (refresh);
- running = HandleEyeIDCMP();
- reveil = DrawingEyes(EyeWnd, &SBitmap, offy);
-
- if (running)
- {
- running = ProcessMsg();
- if (running)
- {
- if ((reveil) && (Parametres.autofront))
- {
- WindowToFront(EyeWnd);
- }
- if (Parametres.autojump)
- {
- running = ProcessJump(TRUE);
- }
- }
- }
- }
- EyeLeft = EyeWnd->LeftEdge;
- EyeTop = EyeWnd->TopEdge;
-
- CloseEyeWindow();
- CloseDownScreen();
- for (i = 0; i < depth; i++)
- FreeRaster(SBitmap.Planes[i],WNDX, WNDY);
- }
- else printf("erreur window\n");
- }
- else printf("erreur screen\n");
-
- while (Dodo)
- {
- if (Parametres.autojump)
- {
- ProcessJump(TRUE);
- }
- else
- Wait(sigflags);
-
- ProcessMsg();
- }
- }
- SortiePropre();
- }
-
- /*****************************************************************************/
- int EyesInfo(void)
- {
- struct IntuiMessage *m;
-
- struct EasyStruct About =
- {
- sizeof(struct EasyStruct),
- 0,
- "AmigaEyes ",
- " AmigaEyes 1.1 (08/11/1994)\n\n"
- " © 1994 Stéphane Poirier\n"
- "E-mail: poiries@asterix.saclay.cea.fr\n\n"
- "Hot Key = < %s >\n\n"
- "This Program is freeware",
- "Ok"
- };
-
- EasyRequest(EyeWnd, &About, 0, hotkey);
-
- while( m = GT_GetIMsg( EyeWnd->UserPort )) GT_ReplyIMsg( m );
- return(1L);
- }
-
- /*****************************************************************************/
- int EyesGoPublic(void)
- {
- EyeCloseWindow();
- Restart = TRUE;
- return(FALSE);
- }
-
- /*****************************************************************************/
- /* Traitement des ToolTypes */
- /*****************************************************************************/
-
- void ToolTypesParameters(struct WBArg *wbarg)
- {
- struct DiskObject *dobj;
- char **toolarray;
- char *s;
- UBYTE ancpriorite;
-
- task = FindTask(NULL);
-
- if((*wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
- {
- toolarray = (char **)dobj->do_ToolTypes;
-
- if (s = (char *)FindToolType(toolarray,"AUTOFRONT"))
- {
- if(MatchToolValue(s,"ON"))
- Parametres.autofront = TRUE;
- if(MatchToolValue(s,"OFF"))
- Parametres.autofront = FALSE;
- }
-
- if (s = (char *)FindToolType(toolarray,"TIMEOUT"))
- {
- if (isalnum(*s))
- Parametres.timeout = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"BACKGROUND"))
- {
- if (isalnum(*s))
- Parametres.fond = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"BORDER"))
- {
- if (isalnum(*s))
- Parametres.bord = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"PUPIL"))
- {
- if (isalnum(*s))
- Parametres.pupille = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"EYELIP"))
- {
- if (isalnum(*s))
- Parametres.paupiere = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"WINDOW"))
- {
- if (isalnum(*s))
- Parametres.fenetre = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"XPOS"))
- {
- if (isalnum(*s))
- EyeLeft = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"YPOS"))
- {
- if (isalnum(*s))
- EyeTop = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"PRIORITY"))
- {
- if ((isalnum(*s)) || ((*s) = '-') || ((*s) = '+'))
- {
- ancpriorite = SetTaskPri(task,atoi(s));
- Parametres.priorite = atoi(s);
- /*
- ** Because of a small bug in AutoJump mode, priorite must be >= -1
- */
- if (Parametres.priorite < -1) Parametres.priorite = -1;
- }
- }
- if (s = (char *)FindToolType(toolarray,"REFRESH"))
- {
- if (isalnum(*s))
- Parametres.refresh = (atoi(s));
- }
- if (s = (char *)FindToolType(toolarray,"CUSTOM_DRAWING"))
- {
- Parametres.drawing = CUSTOM_DRAW;
- }
- if (s = (char *)FindToolType(toolarray,"HOTKEY"))
- {
- strcpy(hotkey, s);
- }
- if (s = (char *)FindToolType(toolarray,"AUTOJUMP"))
- {
- if(MatchToolValue(s,"ON"))
- Parametres.autojump = TRUE;
- if(MatchToolValue(s,"OFF"))
- Parametres.autojump = FALSE;
- }
-
- FreeDiskObject(dobj);
- }
- }
-
- /*****************************************************************************/
-
- void ValeursParDefaut(void)
- {
- Parametres.autofront = FALSE;
- Parametres.autojump = FALSE;
- Parametres.timeout = 30;
- Parametres.pupille = 1;
- Parametres.bord = 1;
- Parametres.fond = 2;
- Parametres.paupiere = 3;
- Parametres.fenetre = 0;
- Parametres.refresh = 2;
- Parametres.priorite = 0;
- Parametres.drawing = STANDARD_DRAW;
- refresh = SLEEP;
- }
-
- /*****************************************************************************/
-
- void OpenLibs(void)
- {
- if (NULL == (DosBase = OpenLibrary("dos.library", 37)))
- {
- errorMessage( "Requires at least V37 dos.library");
- SortiePropre();
- }
-
- if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
- {
- errorMessage( "Requires at least V37 intuition.library");
- SortiePropre();
- }
-
- if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
- {
- errorMessage( "Requires at least V37 graphics.library");
- SortiePropre();
- }
-
- if (NULL == (GadToolsBase = OpenLibrary("gadtools.library", 37)))
- {
- errorMessage( "Requires at least V37 gadtools.library");
- SortiePropre();
- }
-
- if (NULL == (CxBase = OpenLibrary("commodities.library", 37)))
- {
- errorMessage( "Requires at least V37 commodities.library");
- SortiePropre();
- }
- }
-
- /*****************************************************************************/
- void CloseLibs(void)
- {
- if (GfxBase) CloseLibrary(GfxBase);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (CxBase) CloseLibrary(CxBase);
- if (DosBase) CloseLibrary(DosBase);
- if (GadToolsBase) CloseLibrary(GadToolsBase);
- }
-
- /*****************************************************************************/
-
- void CloseDownScreen( void )
- {
- if ( VisualInfo ) {
- FreeVisualInfo( VisualInfo );
- VisualInfo = NULL;
- }
-
- if ( Scr ) {
- UnlockPubScreen( NULL, Scr );
- Scr = NULL;
- }
-
- if ( Font ) {
- CloseFont( Font );
- Font = NULL;
- }
- }
-
- /*****************************************************************************/
-
- void CloseEyeWindow( void )
- {
- if ( EyeWnd ) {
- ClearMenuStrip( EyeWnd );
- CloseWindow( EyeWnd );
- EyeWnd = NULL;
- }
- }
-
- /*****************************************************************************/
-
- void SortiePropre(void)
- {
- CloseEyeWindow();
- CloseDownScreen();
-
- if (EyesBroker) DeleteCxObjAll(EyesBroker);
- if (EyesBrokerMsgPort)
- {
- while(MsgBroker = (CxMsg *)GetMsg(EyesBrokerMsgPort))
- {
- ReplyMsg((struct Message *)MsgBroker);
- }
- DeleteMsgPort(EyesBrokerMsgPort);
- }
-
- CloseLibs();
- exit(0);
- }